package com.example.vae.Home.Find;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.vae.Adapter.FindRecyclerViewAdapter;
import com.example.vae.FindViewModel;
import com.example.vae.R;
import com.example.vae.databinding.FindFragmentBinding;

import java.util.ArrayList;
import java.util.List;

public class FindFragment extends Fragment {

    private FindViewModel mViewModel;
    private FindFragmentBinding binding;

    private FindRecyclerViewAdapter myRecyclerViewAdapter;
    private RecyclerView recyclerView;
    private List<Integer> imageviews=new ArrayList<>();
    private List<String> strings=new ArrayList<>();


    public static FindFragment newInstance() {
        return new FindFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {



        mViewModel = ViewModelProviders.of(requireActivity()).get(FindViewModel.class);
        binding = DataBindingUtil.inflate(inflater, R.layout.find_fragment, container, false);
        binding.setData(mViewModel);
//        设置数据变化 的观察
        binding.setLifecycleOwner(requireActivity());
//       初始化数据
        inititem();

//        加载 mysetting 页面的 recycleview 数据
        myRecyclerViewAdapter=new FindRecyclerViewAdapter(getContext(),imageviews,strings);
        recyclerView=binding.re;
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(myRecyclerViewAdapter);
        return binding.getRoot();

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(FindViewModel.class);
        // TODO: Use the ViewModel
    }

    public void inititem(){
        imageviews.add(R.drawable.ic_fi_1);
        imageviews.add(R.drawable.ic_fi_2);
        imageviews.add(R.drawable.ic_fi_3);
        imageviews.add(R.drawable.ic_fi_4);
        imageviews.add(R.drawable.ic_fi_5);
        imageviews.add(R.drawable.ic_fi_6);
        imageviews.add(R.drawable.ic_fi_7);
        imageviews.add(R.drawable.ic_fi_8);

        strings.add("游戏大厅");
        strings.add("附近的人");
        strings.add("发现群组");
        strings.add("签到");
        strings.add("任务中心");
        strings.add("排行榜");
        strings.add("最热贴排行");
        strings.add("商城");

    }

}
